package com.batch_demo;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.batch_demo.util.HttpClientUtil;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class IncrTest {


    public static void main(String[] args) {


        final CountDownLatch countDownLatch1 = new CountDownLatch(10);

        ExecutorService executorService = Executors.newFixedThreadPool(10);

        try {
            for (int i = 0; i < 10; i++) {

                executorService.submit(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            countDownLatch1.await();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        doMethod();
                    }
                });

                countDownLatch1.countDown();
            }
            executorService.shutdown();
            System.out.println("");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void doMethod() {
        final String url = "http://10.72.254.196:8080/bole/elephant/api/recommended/list";

        Map<String, String> headerMap = new HashMap<>();
//        headerMap.put("Accept", "application/json");
//        headerMap.put("Accept-Encoding", "gzip, deflate");
//        headerMap.put("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8");
//        headerMap.put("Cache-Control", "no-cache");
//        headerMap.put("Connection", "keep-alive");
////        headerMap.put("Content-Length", "0");
//        headerMap.put("Content-Type", "application/json");
//        headerMap.put("Cookie", "uuid=eb191968c2354bb39eb5.1495781526.1.0.0; _ga=GA1.2.1799280315.1494236632; iuuid=6D098313884055CFD82718832AACEA9FD3AE5EFB78A3F141C7B1FB9F31B0D719; ci=10; cityname=%E4%B8%8A%E6%B5%B7; _lxsdk_cuid=160f78135c9c8-0bf0339fac1383-32677403-1fa400-160f78135c9c8; i_extend=H__a100040__b1; webp=1; __utma=74597006.1799280315.1494236632.1515982022.1515982022.1; __utmz=74597006.1515982022.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); hiring-campus-portal_sso_id=603a8c34b71c49e4a493427d75185144");
//        headerMap.put("Host", "campus.it.test.meituan.com");
//        headerMap.put("Origin", "http://campus.it.test.meituan.com");
//        headerMap.put("Pragma", "no-cache");
//        headerMap.put("Referer", "http://campus.it.test.meituan.com/");
//        headerMap.put("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36");
//        headerMap.put("X-Requested-With", "XMLHttpRequest");

//        headerMap.put("Accept", "application/json");
        headerMap.put("host","campus.it.test.meituan.com");
        headerMap.put("x-real-ip","10.20.40.50");
        headerMap.put("x-forwarded-for","172.24.168.223, 10.20.40.50");
        headerMap.put("Connection","close");
//        headerMap.put("content-length","26");
        headerMap.put("x-forwarded-proto","http");
        headerMap.put("Accept","application/json");
        headerMap.put("x-requested-with","XMLHttpRequest");
        headerMap.put("Accept-Encoding","gzip, deflate");
        headerMap.put("Accept-language","zh-cn");
        headerMap.put("Content-Type","application/json");
        headerMap.put("Origin","http://campus.it.test.meituan.com");
        headerMap.put("User-Agent","Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13F69XM/5.2.1.1787");
        headerMap.put("Referer","http://campus.it.test.meituan.com/elephant/recommendHistory?isCloseDXMore=1");
        headerMap.put("Cookie","nx_oauth_112W903118483001=ztqfO2T1Snlnv/9yYfXTS7a5RQzH1UuRTSBDXLo0AFSk/VjcUxJBNxnQZmaruHDq; nx_oauth__refreshtoken_112W903118483001=Xfj4lGDtimnYG3a2uhvQV0trokRxBvLLpJNkhEe1l+KbzPksTNHRrYY2xSkdu7XE; nx_oauth_target_112W903118483001=http%3A%2F%2Fcampus.it.test.meituan.com%2Fbole%2Felephant%2Fapi%2Fstaff%2Fredirect");


        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("pageNo", "1");
        paramMap.put("pageSize", "100");
        JSONObject jsonObject = HttpClientUtil.postForJson(url, JSON.toJSONString(paramMap), headerMap);
        System.out.println(Thread.currentThread().getName() + "-->" + jsonObject);
    }
}
